<?php

class Application_Model_Dao_StudiesType extends Zend_Db_Table_Abstract
{

	protected $_name = 'studies_type';
	protected $_primary = 'id';

	public function init(){
		 
	}
	public function getAll(){
		try {
			$result = $this->fetchAll();
		} catch (Exception $exception) {
				Zend_Registry::get('logger')->log('Exception: '.$exception, Zend_Log::NOTICE);
		}
		return $result;
	}
public function getAllStudiesType(){
		$dbAdapter = Zend_Db_Table::getDefaultAdapter();
		$select = $dbAdapter->select()->from('studies_type');
		$result = $dbAdapter->fetchAll($select);
		return $result;
	}
public function getRowStudiesType($id){
		$dbAdapter = Zend_Db_Table::getDefaultAdapter();
		$select = $dbAdapter->select()->from('studies_type')->where('studies_type.id = \''.$id.'\'');
		$result = $dbAdapter->fetchAll($select);
		return $result;
	}
	
	public function getStudiesTypeByID($id){
		$id = (int)$id;
		$row = $this->fetchRow('id = '.$id);
		if (!$row)
		throw new Exception("Rodzaj studiów o ID $id nie istnieje.");
		return $row->toArray();
	}
	public function getStudiesTypeByDesignation($short){
		$row = $this->fetchRow('short = '.$short);
		if (!$row)
		throw new Exception("Rodzaj studiów o nazwie $short nie istnieje.");
		return $row->toArray();
	}
	public function saveStudiesType($studiesType) {
		$data = array(
			'short' => $studiesType->getShort(),
			'type' => $studiesType->getType(),
			'mode' => $studiesType->getMode(),
			'degree' => $studiesType->getDegree(),
		);
		$result = $this->insert($data);
		return $result;
	}
	public function updateStudiesType($studiesType) {
		$data = array(
			'short' => $studiesType->getShort(),
			'type' => $studiesType->getType(),
			'mode' => $studiesType->getMode(),
			'degree' => $studiesType->getDegree(),
		);
		$result = $this->update($data, 'id = '. (int)$studiesType->getId());
		return $result;
	}
	public function deleteStudiesType($studiesType){
		$result = $this->delete('id =' . (int)$studiesType->getId());
		return $result;
	}
	public function getToSelect(){
		$array = $this->getAll()->toArray(); 
		$typeStudies[''] = "wybierz";
		foreach ($array as $option) {
			$typeStudies[ $option['id'] ] = $option['short' ] ;
		}
		return $typeStudies;
	}
	


}
 